x={
{'X',1,90,67,78,23,43,0 },
{'A',7,90,67,78,23,43,0 },
{'Z',2,90,67,78,23,43,0 },
{'Y',4,90,67,78,23,43,0 }
}

math.randomseed(os.time())
for i=1,4 do
	for j=3,7 do
		x[i][j]=math.random(150)
	end
end	

y={'Xin','Hao','YuWen','Shu','Ying','WuLi','Hua','Zong'}
for k=1,8 do
	if(k==1) then 
		io.write('|')
	end
	io.write(string.format('%' .. string.len(y[k]) .. 's|',y[k]))
end

io.write('\n')

for i=1,4 do
	x[i][8]=x[i][3]+x[i][4]+x[i][5]+x[i][6]+x[i][7]
end


for i=1,4 do
	for j=1,8 do
		if(j==1) then 
			io.write('|')
		end
		io.write(string.format('%' ..string.len(y[j]) ..'s|',x[i][j]))
	end
	io.write('\n')
end

io.write('\n')

for i=1,4 do
	for j=1,8 do
		if(j==1) then 
			io.write('|')
		end
		for k=i,4 do
			if(x[i][8]<x[k][8]) then
				x[i],x[k]=x[k],x[i]
			end
		end
		io.write(string.format('%' ..string.len(y[j]) ..'s|',x[i][j]))
	end
	io.write('\n')
end
io.write('\n')
